<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_expert\Entity\ShusyExpert;

/**
 * @OA\Schema(
 *   schema="ExpertItem",
 *   type="object",
 *   description="ExpertItem"
 * )
 */
class ExpertItem extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_expert';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyExpert) {
      $value = [
        /**
         * @OA\Property(
         *   property="id",
         *   type="integer",
         *   description="ID",
         * ),
         */
        'id' => (int) $this->entity->id,
        /**
         * @OA\Property(
         *   property="name",
         *   type="string",
         *   description="姓名",
         * ),
         */
        'name' => (string) $this->entity->name,
        /**
         * @OA\Property(
         *   property="avatar",
         *   type="string",
         *   description="头像",
         * ),
         */
        'avatar' => $this->getAvatar(file_load($this->entity->avatar)),
        /**
         * @OA\Property(
         *   property="title",
         *   type="string",
         *   description="头衔",
         * ),
         */
        'title' => (string) $this->entity->title,
        /**
         * @OA\Property(
         *   property="phone",
         *   type="string",
         *   description="咨询电话",
         * ),
         */
        'phone' => (string) $this->entity->phone,
        /**
         * @OA\Property(
         *   property="summary",
         *   type="string",
         *   description="简介",
         * ),
         */
        'summary' => (string) $this->entity->summary,
        /**
         * @OA\Property(
         *   property="authentication",
         *   type="integer",
         *   description="认证 0 否 1 是",
         * ),
         */
        'authentication' => (int) $this->entity->authentication,
        /**
         * @OA\Property(
         *   property="experience",
         *   type="string",
         *   description="经验年限",
         * ),
         */
        'experience' => (string) $this->entity->experience,
      ];
      $this->merge($value);
    }
  }

  protected function getAvatar($file) {
    return $this->imageStyleUrl('ExpertItemAvatar', $file);
  }
}
